<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../node_modules/vue/dist/vue.js"></script>
    <style>
        .fade-enter,.fade-leave-to{
            opacity: 0;
        }
        .fade-enter-active,.fade-leave-active{
            transition: opacity 3s;
        }
        

    </style>
</head>
<body>
    <div id="root">
        <!-- 

        -->
        <fade :show="show">
            <div>hello World</div>
        </fade>
        
        <button @click="handleClick">切换</button>
    </div>

    <script>
        // 当你想封装动画效果的时候,建一个公共组件
        Vue.component('fade',{
            // 一个是否显示的属性
            props:['show'],
            // 一个加了插槽的模板
            template:`
                <transition name="fade">
                    <slot v-if="show"></slot>
                </transition>
            `
        })

        var vm  = new Vue({
            el:'#root',
            data:{
                show:true
            },
            methods:{
                handleClick(){
                    this.show = !this.show
                }
            }
        })
    </script>
</body>
</html>